﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using Gao.Poker.Domain;

namespace Gao.Poker.Services
{
    public class SeatingService : BaseService
    {
        public static SeatingService _instance;

        public static SeatingService Instance()
        {
            return _instance ?? (_instance = new SeatingService());
        }

        public List<Seating> GetNullSeat(int competitionId)
        {
            return DbContext.Seatings
                .Where(a => a.CompetitionID == competitionId)
                .Where(a => a.MemberCardNo == null || "".Equals(a.MemberCardNo))
                .ToList();
        }

        public Seating GetMemberSeat(int competitionId,String cardNo)
        {
            return DbContext.Seatings
                .Where(a => a.CompetitionID == competitionId).FirstOrDefault(a => a.MemberCardNo.Equals(cardNo));
        }

        public void Save(Seating seat)
        {
            if(seat == null) return;
            if(seat.ID == 0)
            {
                DbContext.Seatings.Add(seat);
            }
            else
            {
                DbContext.Seatings.Attach(seat);
                DbContext.Entry(seat).State = EntityState.Modified;
            }
            DbContext.SaveChanges();
        }
    }
}
